home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume6 / xchrono / patch1 < prev    next >
Encoding:
Text File  |  1990-04-25  |  13.2 KB  |  480 lines

  1. Path: uunet!cs.utexas.edu!usc!apple!sun-barr!newstop!sun!uunet.UU.NET
  2. From: bischeops!nick@uunet.UU.NET (Nick Bender)
  3. Newsgroups: comp.sources.x
  4. Subject: v06i089: Xchrono, Patch1, Part01/01
  5. Message-ID: <134815@sun.Eng.Sun.COM>
  6. Date: 25 Apr 90 17:17:51 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 469
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: bischeops!nick@uunet.UU.NET (Nick Bender)
  12. Posting-number: Volume 6, Issue 89
  13. Archive-name: xchrono/patch1
  14.  
  15. Following are a few minor fixes/enhancements to xchrono:
  16.  
  17. 1. A new flag/resource "dayFirst" causes dates to be displayed as day/month
  18.    instead of month/day for international support.
  19.  
  20. 2. The -local flag now works correctly when the TZ environment variable is
  21.    not set.
  22.  
  23. 3. A function SetTimezone now does the dirty work of environment munging. It
  24.    has an ifdef HAS_SETENV intended to support systems with setenv/unsetenv
  25.    calls, but this has not been tested because I don't have access to any such
  26.    systems.
  27.  
  28. 4. The AM/PM string in the lower left corner now has a "*" appended if the
  29.    timezone is under daylight savings time.
  30.  
  31. It has been pointed out to me that the "-L <libDirectory>" liker flag on some
  32. systems does not allow a space after the -L. On some systems (HPUX) the space
  33. is required. Since HP claims XPG2 conformance for ld, and I have no other
  34. source of standards, I will bow to HP. This falls under the category of
  35. "trivial gratuitous imcompatibily" anyway.
  36.  
  37. Nuff said,
  38. Nick                         nick%bischeops@uunet.uu.net
  39.  
  40. ------------------------------ snip snip snip snip ------------------------
  41. *** /dev/null   Wed Apr 25 09:42:43 1990
  42. --- patchlevel.h        Wed Apr 25 10:11:07 1990
  43. ***************
  44. *** 0 ****
  45. --- 1 ----
  46. + #define PATCHLEVEL 1
  47. diff -c2 -r xchrono.orig/MultiClock.c xchrono/MultiClock.c
  48. *** xchrono.orig/MultiClock.c    Tue Apr 24 11:31:50 1990
  49. --- xchrono/MultiClock.c    Tue Apr 24 12:03:31 1990
  50. ***************
  51. *** 165,168
  52.       ClassField(updateInterval) = 60;
  53.     ClassField(intervalId) = (XtIntervalId) 0;
  54.     ClassField(clockList) =
  55.       (ClockWidget *) XtMalloc(sizeof(ClockWidget)*CLOCK_LIST_SIZE);
  56.  
  57. --- 165,169 -----
  58.       ClassField(updateInterval) = 60;
  59.     ClassField(intervalId) = (XtIntervalId) 0;
  60. +   ClassField(dayFirst) = FALSE;
  61.     ClassField(clockList) =
  62.       (ClockWidget *) XtMalloc(sizeof(ClockWidget)*CLOCK_LIST_SIZE);
  63. ***************
  64. *** 211,214
  65.   /* A public procedure for changing the update interval */
  66.   void SetClockUpdateInterval (interval)
  67.   {
  68.     if (interval && interval > 0)
  69.  
  70. --- 212,216 -----
  71.   /* A public procedure for changing the update interval */
  72.   void SetClockUpdateInterval (interval)
  73. +      int interval;
  74.   {
  75.     if (interval && interval > 0)
  76. ***************
  77. *** 221,224
  78.   }
  79.   
  80.   /* ARGSUSED */
  81.   static void Initialize (request, new)
  82.  
  83. --- 223,234 -----
  84.   }
  85.   
  86. + /* A public procedure for changing the month/day display order */
  87. + void SetClockDisplayDayFirst (dayFirstFlag)
  88. +      Boolean dayFirstFlag;
  89. + {
  90. +   ClassField (dayFirst) = dayFirstFlag;
  91. +   updateClocks ((Widget) NULL, 0);
  92. + }
  93.   /* ARGSUSED */
  94.   static void Initialize (request, new)
  95. ***************
  96. *** 385,388
  97.   static char tzEnviron[TZ_BUFLEN+3];
  98.   
  99.   extern char *getenv();
  100.   
  101.  
  102. --- 395,427 -----
  103.   static char tzEnviron[TZ_BUFLEN+3];
  104.   
  105. + static void SetTimezone (zone)
  106. +      char *zone;
  107. + {
  108. +   if (zone)
  109. +     {
  110. + #ifdef HAS_SETENV
  111. +       setenv ("TZ", zone, 1);
  112. + #else
  113. +       sprintf (tzEnviron, "TZ=%s", zone);
  114. +       putenv (tzEnviron);
  115. +       tzset ();
  116. + #endif /* HAS_SETENV */
  117. +     }
  118. +   else
  119. +     {
  120. + #ifndef SYSV
  121. + #ifdef HAS_SETENV
  122. +       unsetenv ("TZ");
  123. + #else
  124. +       tzsetwall ();
  125. + #endif /* HAS_SETENV */
  126. + #else
  127. +       sprintf (tzEnviron, "TZ=");
  128. +       putenv (tzEnviron);
  129. +       tzset ();
  130. + #endif /* not SYSV */
  131. +     }
  132. + }
  133.   extern char *getenv();
  134.   
  135. ***************
  136. *** 392,396
  137.   {
  138.     ClockWidget w = (ClockWidget) client_data;
  139. !   long    time_value;
  140.     char localTimezone[TZ_BUFLEN];
  141.     char *tzenv = getenv("TZ");
  142.  
  143. --- 431,436 -----
  144.   {
  145.     ClockWidget w = (ClockWidget) client_data;
  146. !   struct timeval time_value;
  147. !   struct timezone time_zone;
  148.     char localTimezone[TZ_BUFLEN];
  149.     char *tzenv = getenv("TZ");
  150. ***************
  151. *** 405,409
  152.         XtAppAddTimeOut( XtWidgetToApplicationContext( (Widget) *list),
  153.                 ClassField(updateInterval)*1000, updateClocks, NULL );
  154. !   (void) time(&time_value);
  155.     if (tzenv) strcpy (localTimezone, tzenv);
  156.   
  157.  
  158. --- 445,449 -----
  159.         XtAppAddTimeOut( XtWidgetToApplicationContext( (Widget) *list),
  160.                 ClassField(updateInterval)*1000, updateClocks, NULL );
  161. !   gettimeofday (&time_value, &time_zone);
  162.     if (tzenv) strcpy (localTimezone, tzenv);
  163.   
  164. ***************
  165. *** 416,419
  166.     while (count--)
  167.       {
  168.         (*list)->clock.show_second_hand =
  169.       (ClassField(updateInterval) <= SECOND_HAND_TIME);
  170.  
  171. --- 456,461 -----
  172.     while (count--)
  173.       {
  174. +       char *thisZone = (*list)->clock.timezone;
  175.         (*list)->clock.show_second_hand =
  176.       (ClassField(updateInterval) <= SECOND_HAND_TIME);
  177. ***************
  178. *** 420,431
  179.         if (XtIsRealized(*list))
  180.       {
  181. !       if ((*list)->clock.timezone)
  182. !       {
  183. !         sprintf (tzEnviron, "TZ=%s", (*list)->clock.timezone);
  184. !         putenv (tzEnviron);
  185. !         tzset ();
  186. !       }
  187. !       tm = *localtime(&time_value);
  188. !       clock_tic (*list, tm);
  189.         list++;
  190.       }
  191.  
  192. --- 462,473 -----
  193.         if (XtIsRealized(*list))
  194.       {
  195. !       Boolean isDST;
  196. !       SetTimezone (thisZone);
  197. !       tm = *localtime(&time_value.tv_sec);
  198. !       if (thisZone) isDST = tm.tm_isdst;
  199. !       else isDST = time_zone.tz_dsttime;
  200. !       clock_tic (*list, tm, isDST);
  201.         list++;
  202.       }
  203. ***************
  204. *** 432,443
  205.       }
  206.   
  207. !   if (tzenv)
  208. !     {
  209. !       sprintf (tzEnviron, "TZ=%s", localTimezone);
  210. !       putenv (tzEnviron);
  211. !     }
  212. ! #ifndef SYSV
  213. !   else tzsetwall();
  214. ! #endif /* not SYSV */
  215.   }
  216.   
  217.  
  218. --- 474,478 -----
  219.       }
  220.   
  221. !   SetTimezone (tzenv);
  222.   }
  223.   
  224. ***************
  225. *** 444,448
  226.   
  227.   /* ARGSUSED */
  228. ! static void clock_tic(w, tm)
  229.       ClockWidget w;
  230.       struct tm tm; 
  231.  
  232. --- 479,483 -----
  233.   
  234.   /* ARGSUSED */
  235. ! static void clock_tic(w, tm, isdst)
  236.       ClockWidget w;
  237.       struct tm tm;
  238. ***************
  239. *** 446,450
  240.   static void clock_tic(w, tm)
  241.       ClockWidget w;
  242. !     struct tm tm; 
  243.   {
  244.       char    time_string[28];
  245.  
  246. --- 481,486 -----
  247.   static void clock_tic(w, tm, isdst)
  248.       ClockWidget w;
  249. !     struct tm tm;
  250. !         int isdst;
  251.   {
  252.       char    time_string[28];
  253. ***************
  254. *** 522,526
  255.                   if (tm.tm_hour > 12)
  256.                                 tm.tm_hour -= 12;
  257. !                 am_pm = "PM";
  258.                 }
  259.               else am_pm = "AM";
  260.  
  261. --- 558,562 -----
  262.                   if (tm.tm_hour > 12)
  263.                                 tm.tm_hour -= 12;
  264. !                 am_pm = (isdst ? "PM*" : "PM");
  265.                 }
  266.               else am_pm = (isdst ? "AM*" : "PM");
  267. ***************
  268. *** 524,528
  269.                   am_pm = "PM";
  270.                 }
  271. !             else am_pm = "AM";
  272.   
  273.               sprintf (time_string, "%d/%d", tm.tm_mon+1, tm.tm_mday);
  274.  
  275. --- 560,564 -----
  276.                   am_pm = (isdst ? "PM*" : "PM");
  277.                 }
  278. !             else am_pm = (isdst ? "AM*" : "PM");
  279.   
  280.               if (ClassField(dayFirst))
  281. ***************
  282. *** 526,530
  283.               else am_pm = "AM";
  284.   
  285. !             sprintf (time_string, "%d/%d", tm.tm_mon+1, tm.tm_mday);
  286.               {
  287.                 int len = strlen (time_string);
  288.  
  289. --- 562,570 -----
  290.               else am_pm = (isdst ? "AM*" : "PM");
  291.   
  292. !             if (ClassField(dayFirst))
  293. !               sprintf (time_string, "%d/%d", tm.tm_mday, tm.tm_mon+1);
  294. !             else
  295. !               sprintf (time_string, "%d/%d", tm.tm_mon+1, tm.tm_mday);
  296.               {
  297.                 int len = strlen (time_string);
  298. diff -c2 -r xchrono.orig/MultiClock.h xchrono/MultiClock.h
  299. *** xchrono.orig/MultiClock.h    Tue Apr 24 11:31:52 1990
  300. --- xchrono/MultiClock.h    Mon Apr 23 09:24:42 1990
  301. ***************
  302. *** 91,94
  303.   extern void SetClockUpdateInterval(/* int interval */);
  304.   
  305.   #endif /* _XawClock_h */
  306.   /* DON'T ADD STUFF AFTER THIS #endif */
  307.  
  308. --- 91,96 -----
  309.   extern void SetClockUpdateInterval(/* int interval */);
  310.   
  311. + extern void SetClockDisplayDayFirst(/* Boolean flag */);
  312.   #endif /* _XawClock_h */
  313.   /* DON'T ADD STUFF AFTER THIS #endif */
  314. diff -c2 -r xchrono.orig/MultiClockP.h xchrono/MultiClockP.h
  315. *** xchrono.orig/MultiClockP.h    Tue Apr 24 11:31:54 1990
  316. --- xchrono/MultiClockP.h    Mon Apr 23 09:24:36 1990
  317. ***************
  318. *** 87,90
  319.   typedef struct {
  320.     int updateInterval;
  321.     XtIntervalId intervalId;
  322.     ClockWidget *clockList;
  323.  
  324. --- 87,91 -----
  325.   typedef struct {
  326.     int updateInterval;
  327. +   Boolean dayFirst;
  328.     XtIntervalId intervalId;
  329.     ClockWidget *clockList;
  330. diff -c2 -r xchrono.orig/README xchrono/README
  331. *** xchrono.orig/README    Tue Apr 24 11:31:41 1990
  332. --- xchrono/README    Tue Apr 24 12:18:31 1990
  333. ***************
  334. *** 16,20
  335.              [-rv] [-update <seconds>] [-display displayname]
  336.              [-geometry geom]
  337. !            [-width clockWidth] [-height clockHeight] [-local localName]
  338.              [-boston] [-newyork] [-chicago] [-denver] [-la]
  339.              [-hawaii] [-tokyo] [-sydney] [-london]
  340.  
  341. --- 16,21 -----
  342.              [-rv] [-update <seconds>] [-display displayname]
  343.              [-geometry geom]
  344. !            [-width clockWidth] [-height clockHeight]
  345. !            [-dayFirst] [-local localName]
  346.              [-boston] [-newyork] [-chicago] [-denver] [-la]
  347.              [-hawaii] [-tokyo] [-sydney] [-london]
  348. ***************
  349. *** 24,28
  350.   are taken from tztab in the SYSV case, and from /usr/lib/zoneinfo
  351.   otherwise, and as such may or may not be correct (the TZ variable
  352. ! definitions or the city->timezone mappings).
  353.   
  354.   The -local <localName> option causes a clock labeled with <localName>
  355.  
  356. --- 25,32 -----
  357.   are taken from tztab in the SYSV case, and from /usr/lib/zoneinfo
  358.   otherwise, and as such may or may not be correct (the TZ variable
  359. ! definitions or the city->timezone mappings). The AM/PM string in the lower
  360. ! left corner will have an asterisk ("AM*") if the timezone is currently
  361. ! under daylight savings time. The date string in the lower right is by
  362. ! default in month/day format, but can be switched by the -dayFirst flag.
  363.   
  364.   The -local <localName> option causes a clock labeled with <localName>
  365. ***************
  366. *** 74,77
  367.   -----------
  368.   
  369.   % set topDir = <where you installed X>  ## default is /
  370.   % $topDir/usr/bin/X11/imake -I$topDir/usr/lib/X11/config
  371.  
  372. --- 78,85 -----
  373.   -----------
  374.   
  375. + If your systems supports setenv and unsetenv (4.3BSD-tahoe or other) figure out
  376. + how to get HAS_SETENV defined in MultiClock.c (add it to MultiClock.c or figure
  377. + the right thing to do with imake :-).
  378.   % set topDir = <where you installed X>  ## default is /
  379.   % $topDir/usr/bin/X11/imake -I$topDir/usr/lib/X11/config
  380. ***************
  381. *** 77,81
  382.   % $topDir/usr/bin/X11/imake -I$topDir/usr/lib/X11/config
  383.   % make
  384.   
  385.   
  386.  
  387. --- 85,88 -----
  388.   % $topDir/usr/bin/X11/imake -I$topDir/usr/lib/X11/config
  389.   % make
  390.   
  391.   
  392. diff -c2 -r xchrono.orig/xchrono.c xchrono/xchrono.c
  393. *** xchrono.orig/xchrono.c    Tue Apr 24 11:31:43 1990
  394. --- xchrono/xchrono.c    Mon Apr 23 09:23:59 1990
  395. ***************
  396. *** 111,114
  397.     int clockHeight;
  398.     String localName;
  399.     Boolean boston;
  400.     Boolean newyork;
  401.  
  402. --- 111,115 -----
  403.     int clockHeight;
  404.     String localName;
  405. +   Boolean dayFirst;
  406.     Boolean boston;
  407.     Boolean newyork;
  408. ***************
  409. *** 136,139
  410.     {"localName", "LocalName", XtRString, sizeof (String),
  411.        offset(localName), XtRString, "" },
  412.     {"boston", "Boston", XtRBoolean, sizeof(Boolean),
  413.        offset(boston), XtRString, "false" },
  414.  
  415. --- 137,142 -----
  416.     {"localName", "LocalName", XtRString, sizeof (String),
  417.        offset(localName), XtRString, "" },
  418. +   {"dayFirst", "DayFirst", XtRBoolean, sizeof(Boolean),
  419. +      offset(dayFirst), XtRString, "false" },
  420.     {"boston", "Boston", XtRBoolean, sizeof(Boolean),
  421.        offset(boston), XtRString, "false" },
  422. ***************
  423. *** 180,183
  424.   {"-height",     "*clockHeight",        XrmoptionSepArg,    NULL},
  425.   {"-local",    "*localName",        XrmoptionSepArg,    NULL},
  426.   {"-boston",    "*boston",        XrmoptionNoArg,        "on"},
  427.   {"-newyork",    "*newyork",        XrmoptionNoArg,        "on"},
  428.  
  429. --- 183,187 -----
  430.   {"-height",     "*clockHeight",        XrmoptionSepArg,    NULL},
  431.   {"-local",    "*localName",        XrmoptionSepArg,    NULL},
  432. + {"-dayFirst",    "*dayFirst",        XrmoptionNoArg,        "on"},
  433.   {"-boston",    "*boston",        XrmoptionNoArg,        "on"},
  434.   {"-newyork",    "*newyork",        XrmoptionNoArg,        "on"},
  435. ***************
  436. *** 213,217
  437.       (void) printf ("       [-rv] [-update <seconds>] [-display displayname]\n");
  438.       (void) printf ("       [-geometry geom]\n");
  439. !     (void) printf ("       [-width clockWidth] [-height clockHeight] [-local localName]\n");
  440.       (void) printf ("       [-boston] [-newyork] [-chicago] [-denver] [-la]\n");
  441.       (void) printf ("       [-hawaii] [-tokyo] [-sydney] [-london]\n");
  442.  
  443. --- 217,222 -----
  444.       (void) printf ("       [-rv] [-update <seconds>] [-display displayname]\n");
  445.       (void) printf ("       [-geometry geom]\n");
  446. !     (void) printf ("       [-width clockWidth] [-height clockHeight]\n");
  447. !     (void) printf ("       [-dayFirst] [-local localName]\n");
  448.       (void) printf ("       [-boston] [-newyork] [-chicago] [-denver] [-la]\n");
  449.       (void) printf ("       [-hawaii] [-tokyo] [-sydney] [-london]\n");
  450. ***************
  451. *** 392,395
  452.   
  453.       SetClockUpdateInterval (resource.updateInterval);
  454.       XtRealizeWidget (toplevel);
  455.   
  456.  
  457. --- 397,401 -----
  458.   
  459.       SetClockUpdateInterval (resource.updateInterval);
  460. +     if (resource.dayFirst) SetClockDisplayDayFirst (TRUE);
  461.       XtRealizeWidget (toplevel);
  462.   
  463.  
  464. dan
  465. -----------------------------------------------------------
  466.             O'Reilly && Associates
  467.         argv@sun.com / argv@ora.com
  468.        632 Petaluma Ave, Sebastopol, CA 95472 
  469.      800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
  470.     Opinions expressed reflect those of the author only.
  471.